﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FluentValidation;

namespace PdxDemo.FluentValidationDemo
{
    public class ViewModelValidator : AbstractValidator<ViewModel>
    {
        public ViewModelValidator()
        {
            RuleFor(x => x.Intval)
                .NotEmpty()
                .NotEqual(123).WithMessage("123 is not allowed, for some reason");

            RuleFor(x => x.Stringval)
                .Length(1, 12).WithMessage("Stringval must be between 1 and 12 characters");

            RuleFor(x => x.MyBoolean)
                .NotEqual(true).When(vm => vm.Stringval.Length != 12)
                .WithMessage("If MyBoolean is true, Stringval must be 12 chars");
        }
    }

    public interface IHaveValidator
    {
        IValidator GetValidator();
    }

    public enum TEST_ENUM
    {
        [Description("First Choice")]
        First,

        [Description("Second Choice")]
        Second,

        [Description("Third Choice")]
        Third,
    }

    public class ViewModel : ViewmodelBase, IHaveValidator
    {
        static ViewModelValidator validator = new ViewModelValidator();

        public IValidator GetValidator() { return validator; }

        public ViewModel()
        {
            Intval = 123;
            Stringval = "a string";

            MyEnum = TEST_ENUM.Second;
        }

        public int Intval { get; set; }

        [DisplayName("A String Value")]
        public string Stringval { get; set; }

        [DisplayName("My Boolean")]
        public bool MyBoolean { get; set; }

        [DisplayName("Choose Wisely...")]
        public TEST_ENUM MyEnum { get; set; }
    }
}
